﻿Namespace Save

    ''' <summary>
    ''' 列アーカイブ
    ''' </summary>
    ''' <remarks>
    ''' #107 Storageクラスの見直し
    ''' </remarks>
    Public Class ColumnArchive
        Implements IArchive

#Region "プロパティ"
        Private _tableArchive As TableArchive
        ''' <summary>
        ''' テーブルアーカイブ
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property TableArchive() As TableArchive
            Get
                Return _tableArchive
            End Get
            Friend Set(ByVal value As TableArchive)
                _tableArchive = value
            End Set
        End Property

        Private _columnName As String
        ''' <summary>
        ''' 列名
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ColumnName() As String
            Get
                Return _columnName
            End Get
            Friend Set(ByVal value As String)
                _columnName = value
            End Set
        End Property

        Public ReadOnly Property Key As String Implements IArchive.Key
            Get
                Return _columnName
            End Get
        End Property

        Private _archiveValue As Object
        ''' <summary>
        ''' アーカイブ値
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ArchiveValue As Object
            Get
                Return _archiveValue
            End Get
            Friend Set(value As Object)
                _archiveValue = value
            End Set
        End Property
#End Region

        ''' <summary>
        ''' ダーティかどうかを示します
        ''' </summary>
        ''' <param name="instance">検査対象インスタンス</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function IsDirty(instance As Object) As Boolean Implements IArchive.IsDirty
            '実ロジックは列属性で行っています
            Return Me.GetColumnAttribute.IsDirty(instance, Me.ArchiveValue)
        End Function

        ''' <summary>
        ''' 列属性を取得します
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Friend Function GetColumnAttribute() As ColumnAttribute
            Static col As ColumnAttribute = Nothing

            If col Is Nothing Then
                col = (From el In Me.TableArchive.GetTableAttribute.Columns Where el.ColumnName = Me.ColumnName).First
            End If

            Return col
        End Function

    End Class

End Namespace
